// 
//  FDGameView.h
//  FiveDice
//  
//  Created by Chris Born.
//  Copyright 2007 Borngraphics. All rights reserved.
//  
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or any later version.
//  
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//  
//  By contributing code you grant Chris Born and Borngraphics an
//  unlimited, non-exclusive license to your contribution.
//  
//  For support, questions, commercial use, etc...
//  E-Mail: chris <at> borngraphics <dot> com
// 

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIView.h>
#import <UIKit/UIView-Geometry.h>
#import <UIKit/UIControl.h>
#import <UIKit/UITextView.h>
#import <UIKit/UITransformAnimation.h>
#import <UIKit/UIAnimator.h>
#import <UIKit/UIPushButton.h>
#import "WebCore/WebFontCache.h"

#import "FDScoreCardView.h"
#import "FDDefaultsController.h"
#import "FDDiePushButton.h"

@interface NSObject (GameViewDelegateMethods)

- (void)changeStateTo:(int)state;
- (int)currentState;
- (void)updateRollButtonWithLast:(BOOL)withLast;

@end

@interface FDGameView : UIView
{
	id	delegate;
	
	FDDefaultsController 		*defaults;
	
	struct CGRect				_contentRect;
	struct CGRect				_offScreenRect;
	struct CGRect				_onScreenRect;
	
	UITransformAnimation	*translate;
	UIAnimator				*animator;
	
	UITextLabel			*scoreLabel;
	UITextLabel			*turnsLabel;
	
	FDScoreCardView		*scoreCardView;
	
	NSMutableArray		*diceButtons;
	
	// For Game Persistence
	NSMutableArray		*pDiceValues;
	
	int					rollCount;
	int					lastRoll;
	int					turnCount;
	int					diceTotal;
	
	int					dieValues[6];
	int					lastScore;
	
	BOOL				wildcard;
	BOOL				yahtzeeScratched;
	BOOL				fromLastPosition;	
	BOOL 				hasTwo;
	BOOL 				hasThree;
	BOOL 				hasFour;
	BOOL 				hasFive;
	BOOL				hasSmStraight;
	BOOL				hasLgStraight;
	BOOL				shouldClearHolds;
	BOOL				gameIsOver;
	
}

-(id)initWithFrame:(struct CGRect)frame;

#pragma mark Show and Hide Methods
- (void)show;
- (void)hide;
- (void)showScoreCardAfterDelay:(NSTimer *)aTimer;
- (void)hideSelfAfterScoreCardDelay:(NSTimer *)aTimer;

#pragma mark Game Methods
- (void)newGame;
- (void)loadSavedGame;

#pragma mark Dice Methods
- (void)draw5Dice;
- (FDDiePushButton *)diceButtonWithPosition:(int)pos;
- (struct CGRect)rectForDiePosition:(int)pos;
- (void)dieSelected:(FDDiePushButton *)button;
- (void)clearHeldDice;
- (void)resetDice;
- (void)updateDiceValues;
- (void)clearDieValues;

#pragma mark Rolling Methods
- (void)rollDice;
- (void)afterRollDelay:(NSTimer *)aTimer;

#pragma mark Scoring
- (void)validateScoring;
- (void)handleYahtzee;

#pragma mark Score Card Selection Stuff
- (void)clearLastRow;

#pragma mark Turns
- (void)incrementTurn;
- (void)gameOver;

#pragma mark Counters
- (int)rollCount;
- (void)setRollCount:(int)newRollCount;
- (void)resetRollCount;
- (int)turnCount;
- (void)setTurnCount:(int)newTurnCount;
- (void)resetTurnCount;
- (int)lastRoll;
- (void)setLastRoll:(int)newLastRoll;
- (void)resetLastRoll;
- (int)diceTotal;
- (void)setDiceTotal:(int)newDiceTotal;

#pragma mark Accessors
- (BOOL)shouldClearHolds;
- (void)setShouldClearHolds:(BOOL)newShouldClearHolds;
- (BOOL)wildcard;
- (void)setWildcard:(BOOL)newWildcard;
- (int)lastScore;
- (void)setLastScore:(int)newLastScore;
- (NSMutableArray *)pDiceValues;
- (BOOL)yahtzeeScratched;
- (void)setYahtzeeScratched:(BOOL)newYahtzeeScratched;
- (BOOL)gameIsOver;
- (void)setGameIsOver:(BOOL)newGameIsOver;

#pragma mark Score Card Accessors
- (int)selectedRow;
- (void)setSelectedRow:(int)newRow;
- (int)yahtzeeCount;
- (void)setYahtzeeCount:(int)newYahtzeeCount;
- (NSArray *)scoreCardScores;
- (NSArray *)scoreCardSetScores;

#pragma mark Alert Handler
- (void)alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button;

#pragma mark Delegate
- (id)delegate;
- (void)setDelegate:(id)newDelegate;

#pragma mark Dealloc
- (void)dealloc;

@end
